package com.biz.primus.ms.geo.trans;

import com.biz.primus.model.geo.vo.CityItemVo;
import com.biz.primus.ms.geo.dao.po.City;
import com.biz.primus.ms.geo.dao.po.Province;
import com.biz.primus.ms.geo.dao.repository.ProvinceRepository;
import com.google.common.base.Function;
import lombok.AllArgsConstructor;
import org.springframework.beans.BeanUtils;

/**
 *
 *@author JKLiues
 *@date 2017/11/8
 */
@AllArgsConstructor
public class City2CityItemVo implements Function<City, CityItemVo> {
    private ProvinceRepository provinceRepository;

    @Override
    public CityItemVo apply(City input) {
        CityItemVo cityItemVo = new CityItemVo();
        BeanUtils.copyProperties(input, cityItemVo);
        cityItemVo.setIdx(input.getIdxSort());
        cityItemVo.setCityId(input.getId().longValue());
        cityItemVo.setCityName(input.getName());
        Integer provinceId = input.getProvinceId();
        if (provinceId != null) {
            Province province = provinceRepository.findOne(provinceId);
            cityItemVo.setProvinceName(province.getName());
            cityItemVo.setProvinceId(provinceId.longValue());
        } else {
            cityItemVo.setProvinceName("");
        }
        cityItemVo.setIsHotCityText("否");
        if (input.getHotCity() != null && input.getHotCity()) {
            cityItemVo.setIsHotCityText("是");
        }
        return cityItemVo;
    }
}
